home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Record Lib269999262001.psc / modFunctions.bas < prev    next >
Encoding:
BASIC Source File  |  2001-09-26  |  3.4 KB  |  113 lines

  1. Attribute VB_Name = "modFunctions"
  2. Option Explicit
  3.  
  4. Public Sub InitCombo(myCombo As ComboBox, Optional iSelectedRecordID As Integer)
  5.     
  6.     Dim myRecords As clsRecords
  7.     Dim rsResultSet As ADODB.Recordset
  8.     Dim sFieldName As String
  9.     Dim sIDFieldName As String
  10.     Dim iComboID As Integer
  11.     
  12.     Set myRecords = New clsRecords
  13.     Set rsResultSet = New ADODB.Recordset
  14.     With rsResultSet
  15.         .Open myRecords.GetControlSettings(myCombo.Name, sFieldName, sIDFieldName)
  16.         If Not .BOF And Not .EOF Then
  17.             .MoveFirst
  18.         Else
  19.             'Exit Sub
  20.         End If
  21.     End With
  22.     With myCombo
  23.         .Clear
  24.         If (rsResultSet.BOF And rsResultSet.EOF) Then
  25.             .AddItem "no selection possible"
  26.             .Enabled = False
  27.         Else
  28.             .AddItem "choose an item" 'Als je deze tekst in de combo hebben wil
  29.         End If
  30.         .ListIndex = 0 ' ...vergeet dan niet om hieraan een listindex en
  31.         .ItemData(.NewIndex) = -1 '...een itemdata mee te geven....
  32.         While Not rsResultSet.EOF '... en VB gaat vanaf hier zelf verder.
  33.             .AddItem (rsResultSet.Fields(sFieldName).Value)
  34.             .ItemData(.NewIndex) = rsResultSet.Fields(sIDFieldName).Value
  35.             rsResultSet.MoveNext
  36.         Wend
  37.     End With
  38.     
  39.     myCombo.Visible = True
  40.     
  41.     Set rsResultSet = Nothing
  42.     
  43.     Set rsResultSet = New ADODB.Recordset
  44.     
  45.     If iSelectedRecordID <> 0 Then
  46.         rsResultSet.Open myRecords.getComboIDs(iSelectedRecordID)
  47.         setComboboxIndex myCombo, rsResultSet.Fields(sIDFieldName).Value, True
  48.         Set rsResultSet = Nothing
  49.     End If
  50.     
  51. End Sub
  52.  
  53. Public Sub FillListBox(myListbox As ListBox)
  54.     Dim myRecords As clsRecords
  55.     Dim rsResultSet As ADODB.Recordset
  56.     Dim sFieldName As String
  57.     Dim sIDFieldName As String
  58.     
  59.     Set myRecords = New clsRecords
  60.     Set rsResultSet = New ADODB.Recordset
  61.     
  62.     With rsResultSet
  63.         
  64.         .Open myRecords.GetControlSettings(myListbox.Name, sFieldName, sIDFieldName)
  65.         If Not .BOF And Not .EOF Then
  66.             .MoveFirst
  67.             myListbox.Clear
  68.             While Not .EOF
  69.                 With myListbox
  70.                     .AddItem rsResultSet.Fields(sFieldName).Value
  71.                     .ItemData(.NewIndex) = rsResultSet.Fields(sIDFieldName).Value
  72.                 End With
  73.                 .MoveNext
  74.             Wend
  75.         End If
  76.     End With
  77.     
  78.     Set myRecords = Nothing
  79.     Set rsResultSet = Nothing
  80. End Sub
  81.  
  82. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  83. '   Functie voor het "setten" van een combobox
  84. '   Door Richard Scholten
  85. '   06-09-01 'Sub van gemaakt, door Pascal.
  86. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  87. Public Sub setComboboxIndex(ByRef ComboBox As ComboBox, ByVal Value As Variant, Optional ByVal UseItemdata As Boolean = True)
  88.     Dim i As Integer
  89.     Dim bFound As Boolean
  90.     
  91.     bFound = False
  92.     For i = 0 To ComboBox.ListCount - 1
  93.         If UseItemdata Then
  94.             If ComboBox.ItemData(i) = Value Then
  95.                 bFound = True
  96.                 Exit For
  97.             End If
  98.         Else
  99.             If ComboBox.List(i) = Value Then
  100.                 bFound = True
  101.                 Exit For
  102.             End If
  103.         End If
  104.     Next i
  105.     
  106.     If bFound Then
  107.         ComboBox.ListIndex = i
  108.     Else
  109.         ComboBox.ListIndex = 0
  110.     End If
  111. End Sub
  112.  
  113.